package com.caregiver.watch.business.device.service.impl;

import com.caregiver.watch.business.device.model.dto.EnableRealTimeLocationParam;
import com.caregiver.watch.business.device.service.DeviceService;
import com.caregiver.watch.business.user.service.UserDeviceService;
import com.caregiver.watch.business.user.utils.UserInfoUtils;
import com.caregiver.watch.common.exception.business.BusinessException;
import com.caregiver.watch.thirdparty.service.DeviceSettingService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @Description: 设备服务
 * @Author 疆戟
 * @Date 2025/10/12 15:36
 * @Version 1.0
 */
@AllArgsConstructor
@Service
@Slf4j
public class DeviceServiceImpl implements DeviceService {


    private final DeviceSettingService deviceSettingService;
    private final UserDeviceService userDeviceService;



    @Override
    public Boolean triggerRealTimeLocation(EnableRealTimeLocationParam param) {
        log.info("开启手表实时定位:{}", param.getDeviceUuid());
        if (StringUtils.isBlank(param.getDeviceUuid())) {
            throw new BusinessException("设备UUID不能为空");
        }
        // 获取用户 ID
        Long userId = UserInfoUtils.getUserId();
        // 校验用户设备权限
        if (!userDeviceService.checkDevicePermission(userId, param.getDeviceUuid())) {
            throw new BusinessException("用户没有此设备权限");
        }
        return deviceSettingService.getRealtimeLocation(param.getDeviceUuid());
    }
}
